package com.bajiao.common.util.square;

import org.apache.commons.lang.StringUtils;

public enum SquareErrorMessageEnum {


    ADDRESS_VERIFICATION_FAILURE(
            "ADDRESS_VERIFICATION_FAILURE",
            "发卡人拒绝了该请求，因为邮政编码无效。",
            "The card issuer declined the request because the postal code is invalid."),
    CARDHOLDER_INSUFFICIENT_PERMISSIONS(
            "CARDHOLDER_INSUFFICIENT_PERMISSIONS",
            "由于使用卡的位置受到限制，发卡行拒绝了交易。",
            "The card issuer has declined the transaction due to restrictions on where the card can be used."),
    CARD_EXPIRED(
            "CARD_EXPIRED",
            "发卡行拒绝了该请求，因为卡已过期。",
            "The card issuer declined the request because the card is expired."),
    CARD_NOT_SUPPORTED(
            "CARD_NOT_SUPPORTED",
            "该卡在地理区域或MCC商家类别代码中均不受支持",
            "The card is not supported either in the geographic region or by the MCC merchant category code"),
    CARD_TOKEN_EXPIRED(
            "CARD_TOKEN_EXPIRED",
            "提供的卡令牌（一次性）已过期。",
            "The provided card token (nonce) has expired."),
    CARD_TOKEN_USED(
            "CARD_TOKEN_USED",
            "提供的卡令牌（一次性）已用于处理付款。",
            "The provided card token (nonce) was already used to process payment."),


    CVV_FAILURE(
            "CVV_FAILURE",
            "发卡行拒绝了该请求，因为CVV值无效。",
            "The card issuer declined the request because the CVV value is invalid."),
    EXPIRATION_FAILURE(
            "EXPIRATION_FAILURE",
            "卡的到期日期无效或表明卡已过期。",
            "The card expiration date is either invalid or indicates that the card is expired."),
    GENERIC_DECLINE(
            "GENERIC_DECLINE",
            "一个意料之外的问题发生了。",
            "An unexpected error occurred."),
    INSUFFICIENT_FUNDS(
            "INSUFFICIENT_FUNDS",
            "资金来源没有足够的资金来支付这笔款项。",
            "The funding source has insufficient funds to cover the payment."),
    INSUFFICIENT_PERMISSIONS(
            "INSUFFICIENT_PERMISSIONS",
            "Square帐户无权接受此付款。",
            "The Square account does not have the permissions to accept this payment."),
    INVALID_ACCOUNT(
            "INVALID_ACCOUNT",
            "发卡机构无法找到已记录的帐户。",
            "The card issuer was not able to locate account on record."),
    INVALID_CARD_DATA(
            "INVALID_CARD_DATA",
            "提供的卡数据无效。",
            "the provided card data is invalid."),
    INVALID_EMAIL_ADDRESS(
            "INVALID_EMAIL_ADDRESS",
            "提供的电子邮件地址无效。",
            "The provided email address is invalid."),
    INVALID_EXPIRATION(
            "INVALID_EXPIRATION",
            "付款卡的到期日期无效。",
            "The expiration date for the payment card is invalid. "),
    INVALID_FEES(
            "INVALID_FEES",
            "付款的应用程式费用金额太高。",
            "The appfeemoney on a payment is too high."),
    INVALID_LOCATION(
            "INVALID_LOCATION",
            "Square帐户无法在指定区域付款。",
            "The Square account cannot take payments in the specified region. "),
    INVALID_PIN(
            "INVALID_PIN",
            "发卡行拒绝了该请求，因为PIN无效。",
            "The card issuer declined the request because the PIN is invalid."),
    INVALID_POSTAL_CODE(
            "INVALID_POSTAL_CODE",
            "邮政编码格式错误。",
            "The postal code is incorrectly formatted."),
    MANUALLY_ENTERED_PAYMENT_NOT_SUPPORTED(
            "MANUALLY_ENTERED_PAYMENT_NOT_SUPPORTED",
            "必须刷卡，轻击或浸洗卡。通过手动输入卡号尝试进行的付款被拒绝。",
            "The card must be swiped, tapped, or dipped. Payments attempted by manually entering the card number are declined."),
    PAN_FAILURE(
            "PAN_FAILURE",
            "指定的卡号无效。",
            "The specified card number is invalid. "),
    PAYMENT_LIMIT_EXCEEDED(
            "PAYMENT_LIMIT_EXCEEDED",
            "Square拒绝了该请求，因为付款金额超出了该商家的处理限额。", "Square declined the request because the payment amount exceeded the processing limit for this merchant."),
    TRANSACTION_LIMIT(
            "TRANSACTION_LIMIT",
            "发卡机构确定付款金额太高或太低。",
            "The card issuer has determined the payment amount is either too high or too low. "),
    VOICE_FAILURE(
            "VOICE_FAILURE",
            "发卡行拒绝了该请求，因为发卡行要求持卡人进行语音授权。",
            "The card issuer declined the request because the issuer requires voice authorization from the cardholder."),
    ALLOWABLE_PIN_TRIES_EXCEEDED(
            "ALLOWABLE_PIN_TRIES_EXCEEDED",
            "卡已用尽了发卡行设置的可用密码输入重试。",
            " the card has exhausted its available pin entry retries set by the card issuer."),
    BAD_EXPIRATION(
            "BAD_EXPIRATION",
            "卡的到期日期丢失或格式错误。",
            "the card expiration date is either missing or incorrectly formatted."),
    CHIP_INSERTION_REQUIRED(
            "CHIP_INSERTION_REQUIRED",
            "卡发行者要求使用芯片读取器读取卡。",
            " the card issuer requires that the card be read using a chip reader."),
    CARD_PROCESSING_NOT_ENABLED(
            "CARD_PROCESSING_NOT_ENABLED",
            "API调用中提供的位置未启用信用卡处理。",
            "the location provided in the API call is not enabled for credit card processing."),
    TEMPORARY_ERROR(
            "TEMPORARY_ERROR",
            "发生暂时的内部错误。",
            "A temporary internal error occurred. "),
    AMOUNT_TOO_HIGH(
            "AMOUNT_TOO_HIGH",
                    "对于提供的付款来源，请求的付款金额太高。",
                    "The requested payment amount is too high for the provided payment source. "),
    REFUND_DECLINED(
            "REFUND_DECLINED",
                    "请求失败-发卡行拒绝退款。",
                    "Request failed - The card issuer declined the refund.");

    /**
     * 错误编码
     */
    private String code;
    /**
     * 语言 en-us 美国
     */
    private String enus;
    /**
     * 语言 zh-cn 中文
     */
    private String zhcn;

    SquareErrorMessageEnum(String code, String zhcn, String enus) {
        this.enus = enus;
        this.code = code;
        this.zhcn = zhcn;
    }

    public String getEnus() {
        return enus;
    }

    public void setEnus(String enus) {
        this.enus = enus;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getZhcn() {
        return zhcn;
    }

    public void setZhcn(String zhcn) {
        this.zhcn = zhcn;
    }

    public static SquareErrorMessageEnum toEnum(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        for (SquareErrorMessageEnum item : SquareErrorMessageEnum.values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }
}
